function A3bl()  
format long;  

% 读取Excel文件中的数据  
excel_file = 'A3_data_double.xlsx';  % 替换为你的Excel文件名  
data = readtable(excel_file);  

% 假设您要处理的数据在第150列，第3行开始  
signal0 = table2array(data(3:end, 150));  

%signal = signal0;
signal = atan(signal0);

% 使用高斯滤波进行平滑化
sigma = 1;  % 标准差，可以根据需要调整
signal = imgaussfilt(reshape(signal, [], 1), sigma);

% 使用局部极大值和极小值，设置峰值显著性过滤参数  
[peaks, locs_peaks] = findpeaks(signal, 'MinPeakProminence', 0.05, 'MinPeakHeight', 0.1);  
[troughs, locs_troughs] = findpeaks(-signal, 'MinPeakProminence', 0.05, 'MinPeakHeight', 0.1);  

% 上包络线 
start_peak = locs_peaks(1);  
end_peak = locs_peaks(end);  
up_envelope = nan(size(signal));  
x_range_peak = start_peak:end_peak;  
up_envelope(x_range_peak) = spline(locs_peaks, peaks, x_range_peak);  

% 下包络线  
start_trough = locs_troughs(1);  
end_trough = locs_troughs(end);  
down_envelope = nan(size(signal));  
x_range_trough = start_trough:end_trough;  
down_envelope(x_range_trough) = spline(locs_troughs, -troughs, x_range_trough);  
% 使用希尔伯特变换  
analytic_signal = hilbert(signal);  
hilbert_envelope = abs(analytic_signal);  

% 可视化峰值点包络结果  
figure(1);  
hold on;  
plot(signal, 'b', 'DisplayName', 'Original Signal', 'LineWidth', 0.5);  
plot(up_envelope, 'r--', 'DisplayName', 'Upper Envelope (Local Max)');  
plot(down_envelope, 'g--', 'DisplayName', 'Lower Envelope (Local Min)');  
scatter(locs_peaks, signal(locs_peaks), 'r', 'DisplayName', 'Peaks');  
scatter(locs_troughs, signal(locs_troughs), 'g', 'DisplayName', 'Troughs');  
legend;  
title('Signal with Upper and Lower Envelopes (Local Max/Min)');  
xlabel('Sample Index');  
ylabel('Amplitude');  
grid on;  

% 可视化希尔伯特变换结果  
figure(2);  
hold on;  
plot(signal, 'b', 'DisplayName', 'Original Signal', 'LineWidth', 0.5);  
plot(hilbert_envelope, 'm--', 'DisplayName', 'Hilbert Envelope');  
legend;  
title('Signal with Hilbert Envelope');  
xlabel('Sample Index');  
ylabel('Amplitude');  
grid on; 

end  